<?php
class LogAccForm extends Form
{
	function LogAccForm()
	{	
		Form::Form("ManageLogActionForm");		
		CGlobal::$website_title = "Quản trị Log Action";
		
		$this->link_css("style/manage_content.css");
		$this->link_css("style/ui.datepicker.css");
		$this->link_js("javascript/tooltip.js");
		
		$this->link_js("javascript/jquery/ui.datepicker.js");
	}

	function on_submit()
	{
		
	}

	function draw()
	{
		global $display;
		$this->beginForm();
		
		ECLib::get_cats();
		ECLib::get_cities();
		$item = array();
		$mongo_where = array();
		$items = array();
		$result = array();
		$adList = array();	
		$items_temp = array();	
		
		$paging = "";
		$condition = "";
		$item_ids = "";	
		$badword = "";	
		
		$str_ids_arr = "";
		$str_ids = "";
		$str_del_uis = "";
		$limit = "";	
		$total 	= 0;
		$table = "phpclass_ad";	
			
		// Tim ID tin
		$company_id = Url::getParamInt("company_id",0);		
		$display->add("company_id",$company_id);
		$type = Url::getParam("type",0);		
		$display->add("type",$type);
		// Tim ID user
		$user_id = Url::getParamInt("user_id",0);
		$display->add("user_id",$user_id);
		
		// Tim IP
		$ip = Url::getParam("ip");
		$display->add("ip",$ip);
		
		// Tim tu ngay
		$created_time_from = Url::getParam("created_time_from");
		$display->add("created_time_from",$created_time_from);
		
		// Tim den ngay
		$created_time_to = Url::getParam("created_time_to");
		$display->add("created_time_to",$created_time_to);
		
		if($company_id)
		{
			$condition .= ($condition=="")?"company_id=$company_id":" AND company_id=$company_id";
		}
		
		if($user_id)
		{
			$condition .= ($condition=="")?"user_id=$user_id":" AND user_id=$user_id";
		}
		
		if($type !=0)
		{			
			$condition .= ($condition=="")?"type =$type":" AND type=$type";
		}
		
		
		if($created_time_from)
		{
			$date_arr = explode("-",$created_time_from);
			if(isset($date_arr[0]) && isset($date_arr[1]) && isset($date_arr[2]))
			$created_time_from = mktime(0,0,0,(int)$date_arr[1],(int)$date_arr[0],(int)$date_arr[2]);
		}
		
		if($created_time_to)
		{
			$date_arr = explode("-",$created_time_to);
			if(isset($date_arr[0]) && isset($date_arr[1]) && isset($date_arr[2]))
			$created_time_to = mktime(23,59,59,(int)$date_arr[1],(int)$date_arr[0],(int)$date_arr[2]);
		}		
		
		if($created_time_from)
		{																	
			$condition .= ($condition=="")?" time_act >= $created_time_from":" AND time_act >= $created_time_from";
		}
		
		if($created_time_to)
		{																	
			$condition .= ($condition=="")?" time_act <= $created_time_to":" AND time_act <= $created_time_to";
		}
		
		$condition = $condition?" WHERE ".$condition:"";		
		
		$sql 	= "SELECT COUNT(*) AS total_rows FROM log_account $condition";		
		$total 	= DB::fetch($sql,"total_rows",0);
		
    	if($total)
    	{
			$paging = ECPaging::pagingSE($limit,$total,100,10,"page_no",true,"action","Trang");
			
    		$sql = "SELECT * FROM log_account $condition ORDER BY id DESC $limit";
    		
    		$result = DB::query($sql);
		$keys=0;
		while ($row = mysql_fetch_assoc($result))
			{
				
				$item[$keys]['id'] = $row['id'];
				$item[$keys]['type'] = $row['type'];
				$item[$keys]['user_id'] = $row['user_id'];
				//$item[$keys]['company_id'] = $row['company_id'];
				$item[$keys]['level'] = $row['level'];
				$item[$keys]['user_add'] = $row['user_add'];
				$item[$keys]['user_email'] = $row['user_email'];
				$item[$keys]['time_act'] = ECLib::formatDateLong($row['time_act']);
				$item[$keys]['ip'] = $row['ip'];
				$item[$keys]['note'] = $row['note'];
				$keys++;
				
			}
		
		//System::debug($item);
		
		
		
		
		}
		$display->add("items",$item);
		$display->add("page_no",(int)Url::get("page_no"));
		$display->add("paging",$paging);
		$display->output("LogAcc");
		
		$this->endForm();
	}
}
?>